﻿//********************************************************************************//
//创建日期：<创建日期，2016-03-14>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//功能说明：处理发票相关
//********************************************************************************//
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Entity;
using BLL;
using BLL.Access;
using YXYLCommon;
using System.Web;
using System.Web.SessionState;

namespace Web.ashx.YSZW
{
    /// <summary>
    /// FaPiao 的摘要说明
    /// </summary>
    public class FaPiao : IHttpHandler,IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int? rsno = -1;
            string rsmsg = "";
            if(context.Request["op"]=="RK")
            {
                int inputcount = int.Parse(context.Request["InputCount"]);
                string startno = context.Request["StartNo"];
                string endno = context.Request["EndNo"];
                DateTime inputtime = DateTime.Parse(context.Request["InputTime"]);
                string inputoperator = context.Request["InputOperator"];
                int usetype = int.Parse(context.Request["UseType"]);
                new SpHelper().P_YSZW_FAPIAORK(BusinessTool.WType,inputcount,startno,endno,inputtime,inputoperator,usetype,out rsno,out rsmsg);
                JsonRs rs = new JsonRs(rsno == 1, rsmsg, null);
                context.Response.Write(JsonConvert.SerializeObject(rs));
            }
            else if (context.Request["op"] == "RKList")
            {
                List<YSZWFaPiaoKC> list = new DALYSZWFaPiaoKC().Get(BusinessTool.WType,null);
                context.Response.Write(JsonConvert.SerializeObject(list));
            }
            else if (context.Request["op"] == "RKQX")
            {
                int id = int.Parse(context.Request["id"]);
                string caozuor = LoginInfo.CurrentUser.UserName.ToString();
                DateTime caozuosj = BusinessTool.GetDataBaseDateTime();
                new SpHelper().P_YSZW_FAPIAORKQX(BusinessTool.WType,id, caozuor, caozuosj, out rsno, out rsmsg);
                JsonRs rs = new JsonRs(rsno == 1, rsmsg, null);
                context.Response.Write(JsonConvert.SerializeObject(rs));
            }
            else if (context.Request["op"] == "KCList")
            {
                List<YSZWFaPiaoKC> list = new DALYSZWFaPiaoKC().Get(BusinessTool.WType,0);
                context.Response.Write(JsonConvert.SerializeObject(list));
            }
            else if (context.Request["op"] == "KCMXList")
            {
                List<YSZWFaPiaoKCMX> list = new DALYSZWFaPiaoKCMX().Get(BusinessTool.WType,int.Parse(context.Request["id"]));
                context.Response.Write(JsonConvert.SerializeObject(list));
            }
            else if (context.Request["op"] == "LY")
            {
                int fapiaokcmxid = int.Parse(context.Request["eFaPiaoKCMXID"]);
                string zhandian = context.Request["eZhanDian"];
                string guanlik = context.Request["eGuanLiK"];
                int count = int.Parse(context.Request["eCount"]);
                string start=context.Request["eStartNo"];
                string end = context.Request["eEndNo"];
                DateTime time = DateTime.Parse(context.Request["eTime"]);
                string user = context.Request["eUser"];
                string caozuor = LoginInfo.CurrentUser.UserID.ToString();
                DateTime caozuosj = BusinessTool.GetDataBaseDateTime();
                new SpHelper().P_YSZW_FAPIAOLY(BusinessTool.WType,fapiaokcmxid, zhandian, guanlik, start, end, count, user, time, caozuor, caozuosj, out rsno, out rsmsg);
                JsonRs rs = new JsonRs(rsno == 1, rsmsg, null);
                context.Response.Write(JsonConvert.SerializeObject(rs));
            }
            else if (context.Request["op"] == "LYList")
            {
                List<YSZWFaPiaoLY> list = new DALYSZWFaPiaoLY().Get(BusinessTool.WType,null, null);
                context.Response.Write(JsonConvert.SerializeObject(list));
            }
            else if (context.Request["op"] == "LYQX")
            {
                int id = int.Parse(context.Request["id"]);
                string caozuor = LoginInfo.CurrentUser.UserName.ToString();
                DateTime caozuosj = BusinessTool.GetDataBaseDateTime();
                new SpHelper().P_YSZW_FAPIAOLYQX(BusinessTool.WType,id, caozuor, caozuosj, out rsno, out rsmsg);
                JsonRs rs = new JsonRs(rsno == 1, rsmsg, null);
                context.Response.Write(JsonConvert.SerializeObject(rs));
            }
            else if (context.Request["op"] == "FiaoPiaoHMHQ")
            {
                int count = int.Parse(context.Request["count"]);
                string fapiaohms = "";
                new SpHelper().P_YSZW_FAPIAOHMHQ(BusinessTool.WType, count, out fapiaohms, out rsno, out rsmsg);
                JsonRs rs = new JsonRs(rsno == 1, rsmsg, fapiaohms);
                context.Response.Write(JsonConvert.SerializeObject(rs));
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}